export enum Env {
  Sit = 'sit',
  Beta = 'beta',
}
let env: Env | undefined;
export function getEnv() {
  return env;
}
getEnvTrigger();
/** 确保在调用`getEnv`之前执行 */
function getEnvTrigger() {
  Manycore.Miniapp.getUrlExtraParam();
}
window.addEventListener('message', ({ source, origin }) => {
  if (source !== window.parent) return;
  if (checkSitEnv(origin)) {
    env = Env.Sit;
  } else if (checkBetaEnv(origin)) {
    env = Env.Beta;
  }
});
/** 检测小程序1ocal,sit环境 */
const checkSitEnv = (origin: string) =>
  origin.startsWith('http://localhost') || origin.startsWith('https://sit');
/** 检测小程序beta环境 */
const checkBetaEnv = (origin: string) => origin.startsWith('https://beta');
